public class FonctionDegre2 {
	protected double a;
	protected double b;
	protected double c;

	/**
	 * Creates a quadratic function computer
	 * @param a aX²
	 * @param b bX
	 * @param c constant
	 */
	public FonctionDegre2 (double a, double b, double c) {
		this.a = a;
		this.b = b;
		this.c = c;
	}
	
	/**
	 * Computes roots of the quadratic function
	 * @return An array of 2 roots (maybe the same) or null if the function has no roots. 
	 */
	public double[] getRoots() {
		double delta = (b*b)-(4*a*c);
		if (delta < 0)
			return null;
		else {
			double rs = Math.sqrt(delta);
			double first = ((-b)+rs)/(2*a);
			double second = ((-b)-rs)/(2*a);
			return new double[]{first, second};
		}
	}
	
	/**
	 * Computes a single point
	 * @param x X to be injected in aX²+bX+c
	 * @return The function's image
	 */
	public double getPoint (double x) {
		return (a*x*x)+(b*x)+c;
	}
}
